#include <iostream>
#include <math.h>
#include "d_Math.h"

using namespace d_Math;

d_Vec3f::d_Vec3f()
{
	p[0] = p[1] = p[2] = 0;
}

d_Vec3f::d_Vec3f(const d_Vec3f &v)
{
	p[0] = v[0];
	p[1] = v[1];
	p[2] = v[2];
}

d_Vec3f::d_Vec3f(float x, float y, float z)
{
	p[0] = x;
	p[1] = y;
	p[2] = z;
}

void d_Vec3f::normalize()
{
	float length = len(*this);
	p[0] /= length;
	p[1] /= length;
	p[2] /= length;
}

d_Vec3f d_Vec3f::rotateByY(float theta)
{
	return d_Vec3f(p[0]*cos(theta)+p[2]*sin(theta),0, -p[0]*sin(theta)+p[2]*cos(theta));
}

float &d_Vec3f::operator [] (int i)
{
	if(i>3)
	{
		std::cout << "Bad index for vector!" << std::endl;
		return p[0];
	}
	return p[i];
}

float d_Vec3f::operator [] (int i) const
{
	if(i>3)
	{
		std::cout << "Bad index for vector!" << std::endl;
		return p[0];
	}
	return p[i];
}

d_Vec3f d_Vec3f::operator + (const d_Vec3f v) const
{
	d_Vec3f res(p[0]+v[0], p[1]+v[1], p[2]+v[2]);
	return res;
}

d_Vec3f d_Vec3f::operator - (const d_Vec3f v) const
{
	d_Vec3f res(p[0]-v[0], p[1]-v[1], p[2]-v[2]);
	return res;
}

d_Vec3f d_Vec3f::operator * (const float a) const
{
	d_Vec3f res(p[0]*a, p[1]*a, p[2]*a);
	return res;
}

d_Vec3f d_Vec3f::operator / (const float a) const
{
	d_Vec3f res(p[0]/a, p[1]/a, p[2]/a);
	return res;
}

